package demo3;

import java.util.ArrayList;

public class Text {
    public static void main(String[] args) {
        ArrayList<Phone> list = new ArrayList<>();

        Phone p1 = new Phone("xiaomi",1000);
        Phone p2 = new Phone("iphoen",9000);
        Phone p3 = new Phone("huaiwei",2000);

        list.add(p1);
        list.add(p2);
        list.add(p3);


        ArrayList<Phone> p = PhoneInfo(list);

        for (int i = 0; i < p.size(); i++) {
            System.out.println(p.get(i).getBrand() + "," + p.get(i).getPrice());
        }
    }
    //返回多个元素
    private static ArrayList<Phone> PhoneInfo(ArrayList<Phone> list){
        ArrayList<Phone> ArrayPhone = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getPrice() < 3000){
                ArrayPhone.add(list.get(i));
            }
        }
        return ArrayPhone;
    }
}
